package com.shujia.wyh.day21;

//姓名,语文成绩,数学成绩,英语成绩
public class Student implements Comparable<Student> {
    private String name;
    private int chinese;
    private int math;
    private int english;

    public Student() {
    }

    public Student(String name, int chinese, int math, int english) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    //求总分的方法
    public int getSumScore() {
        return chinese + math + english;
    }

    @Override
    public int compareTo(Student o) {
        //主要条件：总分按照从高到低的顺序进行输出
        int i = o.getSumScore() - this.getSumScore();
        //隐含条件：
        //总分一样，语文还不一定一样
        int i2 = (i == 0) ? o.chinese - this.chinese : i;
        //语文成绩一样，数学成绩还不一定一样
        int i3 = (i2 == 0) ? o.math - this.math : i2;
        //成绩比较完后，姓名不一定一样
        int i4 = (i3 == 0) ? o.name.compareTo(this.name) : i3;

        return i4;
    }
}
